package struct.gameinfo.ui
{
	import collection.DataCollection;
	
	import com.common.displayObjects.ComponentChildren;
	
	import flash.display.Graphics;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	
	public class GameInfoUI extends ComponentChildren
	{
		public var curScore:int = 0; //当前得分
		public function GameInfoUI()
		{
			super(Main.application.width, 40);
		}
		
		private var txtScore:TextField; //得分
		private var txtLife:TextField; //生命
		override protected function createChildren():void
		{
			super.createChildren();
			var g:Graphics = graphics;
			g.beginFill(0x00);
			g.drawRoundRect(0, 0, width, height, 4, 4);
			g.endFill();
			
			txtScore = new TextField();
			txtScore.selectable = false;
			txtScore.defaultTextFormat = new TextFormat("黑体", 20, 0xff, true);
			txtScore.autoSize = TextFieldAutoSize.LEFT;
			txtScore.height = 20;
			txtScore.text = "得分:0";
			txtScore.x = 20;
			addChild(txtScore);
			
			txtLife = new TextField();
			txtLife.selectable = false;
			txtLife.defaultTextFormat = new TextFormat("黑体", 20, 0xff, true);
			txtLife.autoSize = TextFieldAutoSize.LEFT;
			txtLife.height = 20;
			txtLife.text = "生命:" + String(DataCollection.LIFE);
			txtLife.x = width - txtLife.width;
			addChild(txtLife);
		}
		
		public function addScore(score:int):void
		{
			curScore += score;
			txtScore.text = "得分:" + String(curScore);
		}
		
		public function resetLife():void
		{
			txtLife.text = "生命:" + DataCollection.LIFE;
		}
	}
}